package com.arronlong.httpclientutil.evictor;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Test {
    public static void main(String[] args) throws ParseException {
        /*Calendar cal = Calendar.getInstance();

        cal.add(Calendar.DATE,-1);

        String yesterday = new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime());

        System.out.println(yesterday);*/

        /*Calendar calendar = Calendar.getInstance();
        //如果今天是星期天，就获取上一周
        calendar.setTime(new Date());
        boolean isFirstSunday = (calendar.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY);
        if(isFirstSunday == true){
            calendar.add(Calendar.DAY_OF_WEEK,-7);
            calendar.add(Calendar.DATE, 1);//日期自增
        }else {
            calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        }
        System.out.println(calendar.getTime());*/


    }
    public static String liveTimes(Long seconds){
        Long temp= 0L;
        StringBuffer sb=new StringBuffer();
        temp = seconds/3600;
        sb.append((temp<10)?""+temp+"小时":""+temp+"小时");
        temp=seconds%3600/60;
        sb.append((temp<10)?""+temp+"分":""+temp+"分");
        temp=seconds%3600%60;
        sb.append((temp<10)?""+temp+"秒":""+temp+"秒");
        return sb.toString();
    }


    public static Date getDate(Date date){
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DATE, -1);
		for (int i = 0; i < 7; i++) {
            Map<String, Object> map = new HashMap<>();
            calendar.add(Calendar.DATE, 1);//日期自增
        }
		return date;
    }

    public static Date getCurrentWeekDateBegin(Date date){

        Calendar now = Calendar.getInstance();
        //一周第一天是否为星期天
        boolean isFirstSunday = (now.getFirstDayOfWeek() == Calendar.SUNDAY);
        int weekDay = now.get(Calendar.DAY_OF_WEEK);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        return calendar.getTime();
    }

    public static Date getLastWeekDate(Date date){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_WEEK,-14);
        calendar.add(Calendar.DATE, 1);//日期自增
        return calendar.getTime();
    }

    public static Date getCurrentFirstDayOrLastWeekFirstDay(Date date){
        Calendar now = Calendar.getInstance();
        //如果今天是星期天，就获取上一周
        boolean isFirstSunday = (now.getFirstDayOfWeek() == Calendar.SUNDAY);
        Calendar calendar = Calendar.getInstance();
        if(isFirstSunday == true){
            calendar.setTime(date);
            calendar.add(Calendar.DAY_OF_WEEK,-14);
            calendar.add(Calendar.DATE, 1);//日期自增
        }else {
            calendar.setTime(date);
            calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
            calendar.add(Calendar.DATE, 1);
        }
        return calendar.getTime();
    }

    public static Date getLastWeekDateByMonday(Date date){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_WEEK,-7);
        calendar.add(Calendar.DATE, 1);//日期自增
        return calendar.getTime();
    }

    public static Date getLastWeekDateFirstOrBefortLastFirst(Date date){
        Calendar now = Calendar.getInstance();
        //如果今天是星期天，就获取上一周
        boolean isFirstSunday = (now.getFirstDayOfWeek() == Calendar.SUNDAY);
        Calendar calendar = Calendar.getInstance();
        if(isFirstSunday == true){
            calendar.setTime(date);
            calendar.add(Calendar.DAY_OF_WEEK,-14);
            calendar.add(Calendar.DATE, 1);//日期自增
        }else {
            calendar.setTime(date);
            calendar.add(Calendar.DAY_OF_WEEK,-7);
            calendar.add(Calendar.DATE, 1);//日期自增
        }
        return calendar.getTime();
    }

    public static Date getLastWeekDates(Date date){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_WEEK,-7);
        return calendar.getTime();
    }

}
